/**
 * @autor Flower
 * @descrption 个人中心
 */

import HttpService from '../../../services/HttpService'
import ApiUrl from '../../../services/ApiUrl'
import Util from '../../../services/Util'
import EditType from '../member/edit-types'
var app = getApp();
app.getUserInfo();
Page({
  data: {
    userInfo: wx.getStorageSync('profile') || {}
  },
  //去编辑个人信息页面
  editProfile: function(){
    let self = this, userData = self.data.userInfo;
    let type = '';
    if( userData.is_profile_completed ){
      type = EditType.profile.editInfo+'&name='+userData.member.name+'&birthday='+userData.member.birthday+'&id='+userData.member.id+'&avatar='+userData.member.avatar;
    }else{
      type = EditType.profile.completeInfo;
    }
    wx.navigateTo({ url:"/pages/user/member/edit-member/edit-member?type="+type })
  },
  //更新页面数据
  updatePageData: function(){
    let self = this;
    self.setData({
        userInfo: wx.getStorageSync('profile') || {}
    });
  },
  //获取用户信息
  // getProfile: function(){
  //   let self = this;
  //   let opts = {
  //     apiObj: ApiUrl.user
  //   }
  //   HttpService.accessAPI(opts).then(function(result){
  //     console.log( 'get profile success', result.data );
  //     if(result.data.member && typeof result.data.member == 'object'){
  //       result.data.member.gender = result.data.member.gender == 'male'?'男': '女';
  //       result.data.member.avatar = result.data.member.avatar? result.data.member.avatar+'?imageView2/1/w/200/h/200':'/images/avatar-placeholder.jpeg';
  //       result.data.member.birthday = Util.unixToDate(result.data.member.birthday);
  //     }
  //     wx.setStorage( { key:'profile', data: result.data } );
  //     self.setData({
  //       userInfo: result.data
  //     });
  //   })
  // },
  onLoad: function () {
  },
  onShow: function(){
      let self = this;
      self.updatePageData();
  }
})